package com.ljx.offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/3/29
 * ClassName: C_32_3
 */

public class C_32_3 {
    List<List<Integer>> lists = new ArrayList<>();
    public List<List<Integer>> levelOrder(TreeNode root) {
        deep(0,root);
        return lists;
    }

    void deep(int depth, TreeNode root) {
        if (root != null) {
            if (lists.size() <= depth) {
                lists.add(new ArrayList<>());
            }
            if (depth % 2 == 0) {
                lists.get(depth).add(root.val);
            } else {
                lists.get(depth).add(0, root.val);
            }
            deep(depth + 1, root.left);
            deep(depth + 1, root.right);
        }
    }
    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }


}
